import App from './App'

// #ifndef VUE3
import Vue from 'vue'
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
	...App
})
app.$mount()
// #endif

// #ifdef VUE3
import uView from './uni_modules/vk-uview-ui';
import io from '@hyoga/uni-socket.io';
import store from './store'
import {
	createSSRApp
} from 'vue'
import Vuex from 'vuex'
import appShowModel from '@/components/chatCard/appShowModel.js'
import 'default-passive-events'
import base from '@/api/baseUrl.js'
uni.$showModalhide = null
const promiseToArr = (promise, errorExt = null) => {
	return promise
		.then((data) => {
			return [null, data];
		})
		.catch((err) => {
			if (errorExt) {
				Object.assign(err, errorExt);
			}
			return [err, undefined];
		})
}
// 消息提示框弹窗
const msgAlert = (msg, success = () => {}) => {
	uni.showToast({
		title: msg || '网络异常，请稍后重试',
		icon: 'none',
		duration: 2000,
		success: success,
	})
}

const userinfo = uni.getStorageSync('userinfo')
// 引入 uView UI
export function createApp() {
	const app = createSSRApp(App)
	
	app.provide('$socket', new io(base, {
		query: {
			userid: userinfo.userid,
			username: userinfo.username
		},
		transports: ['websocket', 'polling'],
		timeout: 5000,
	}))
	app.provide('$try', promiseToArr)
	app.provide('$msgAlert', msgAlert)
	app.use(store)
	app.use(uView)
	app.use(appShowModel)
	return {
		app,
		Vuex
	}
}
// #endif